package acwing._1_1AlgorithmBasic._4Math;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._4Math
 * @File : Q0872.java
 * @Author : WangRuoyu
 * @Date : 2023/4/4 16:02
 */

import java.io.*;

public class Q0872 {
//    static int gcd(int a, int b) {
//        return b == 0 ? a : gcd(b, a % b);
//    }

    static int gcd(int a, int b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        int c = a - b;
        return gcd(Math.max(b, c), Math.min(b, c));
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);

        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            wr.write(gcd(a, b) + "\n");
        }

        wr.flush();
    }
}
